package com.sphd.emanu.activity.ordersdetail;

import android.content.Context;

import com.google.gson.JsonObject;
import com.sphd.emanu.mvp.BasePresenterImpl;
import com.sphd.emanu.pojo.order.Order;
import com.sphd.emanu.utils.GsonUtil;
import com.wzutils.L;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class OrdersdetailPresenter extends BasePresenterImpl<OrdersdetailContract.View> implements OrdersdetailContract.Presenter {

    @Override
    public void selectOrderItems(int id) {
        emanuService.selectOrderItems(id).enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                L.e(response.toString());
                Order order = GsonUtil.GsonToBean(response.body(), Order.class);
                mView.setBean(order);
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
    }
    @Override
    public void updateOrderStatus(Integer orderId, int status) {
        emanuService.updateOrderStatus(orderId, status).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                mView.recRes(res(response),status);
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }
}
